package cn.iocoder.yudao.module.trade.controller.app.order;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.CustomerTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.CustomerTradeOrderItemRespVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author 梁富贵
 * @Date 2024/10/16
 **/
@Tag(name = "商城-客户交易订单")
@RestController
@RequestMapping("/trade/customer-order")
@Validated
@Slf4j
public class CustomerTradeOrderController {

    @Resource
    private TradeOrderQueryService tradeOrderQueryService;

    @Schema(description = "获取订单")
    @GetMapping("/name-and-orderID")
    public CommonResult<PageResult<CustomerTradeOrderItemRespVO>> getOrder(@Valid CustomerTradeOrderPageReqVO reqVO) {
        PageResult<TradeOrderItemDO> pageResult = tradeOrderQueryService.getOrderItemListByOrderIdAndSpuName(reqVO);
        return CommonResult.success(new PageResult<>(BeanUtils.toBean(pageResult.getList(), CustomerTradeOrderItemRespVO.class), pageResult.getTotal()));
    }

    @Schema(description = "根据订单状态获取交易订单")
    @GetMapping("/get")
    public CommonResult<PageResult<CustomerTradeOrderItemRespVO>> getOrderByStatus(@RequestParam(value="status") Integer status) {
        PageResult<TradeOrderItemDO> pageResult = tradeOrderQueryService.getOrderItemListByStatus(status);
        return CommonResult.success(new PageResult<>(BeanUtils.toBean(pageResult.getList(), CustomerTradeOrderItemRespVO.class), pageResult.getTotal()));
    }
}
